package com.ruoyi.system.controller;

import com.ruoyi.common.core.domain.KeyValueVo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.security.annotation.PreAuthorize;
import com.ruoyi.system.domain.SysDeptJoin;
import com.ruoyi.system.service.ISysDeptJoinService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 学校入驻信息Controller
 *
 * @author WJH
 * @date 2022-08-02
 */
@RestController
@RequestMapping("/system/SysDeptJoin")
public class SysDeptJoinController extends com.ruoyi.common.core.web.controller.BaseController {
    @Autowired
    private ISysDeptJoinService sysDeptJoinService;

    /**
     * 查询学校入驻信息列表
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "system:SysDeptJoin:list")
    //@ApiOperation(value = "获取学校入驻信息列表")
    @GetMapping("/getSysDeptJoinList")
    public com.ruoyi.common.core.web.page.TableDataInfo getSysDeptJoinList(SysDeptJoin sysDeptJoin) {
        startPage();
        List<SysDeptJoin> list = sysDeptJoinService.selectSysDeptJoinList(sysDeptJoin);
        return getDataTable(list);
    }


    /**
     * 获取学校入驻信息详细信息
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "system:SysDeptJoin:query")
    //@ApiOperation(value = "获取学校入驻信息详情")
    @GetMapping(value = "/getSysDeptJoinById")
    public com.ruoyi.common.core.web.domain.AjaxResult getSysDeptJoinById(@RequestParam("deptJoinId") Long deptJoinId) {
        return com.ruoyi.common.core.web.domain.AjaxResult.success(sysDeptJoinService.selectSysDeptJoinByDeptJoinId(deptJoinId));
    }

    /**
     * 新增学校入驻信息
     */
    @PreAuthorize
    @Log(title = "新增学校入驻信息", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增学校入驻信息")
    @PostMapping(value = "/addSysDeptJoin")
    public com.ruoyi.common.core.web.domain.AjaxResult addSysDeptJoin(@RequestBody SysDeptJoin sysDeptJoin) {
        sysDeptJoin.setCreateTime(System.currentTimeMillis());
        return toAjax(sysDeptJoinService.save(sysDeptJoin));
    }

    /**
     * 修改学校入驻信息
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "system:SysDeptJoin:edit")
    @Log(title = "学校入驻信息", businessType = BusinessType.UPDATE)
    //@ApiOperation(value = "修改学校入驻信息")
    @PostMapping(value = "/editSysDeptJoin")
    public com.ruoyi.common.core.web.domain.AjaxResult editSysDeptJoin(@RequestBody SysDeptJoin sysDeptJoin) {
        return toAjax(sysDeptJoinService.updateSysDeptJoin(sysDeptJoin));
    }

    /**
     * 删除学校入驻信息
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "system:SysDeptJoin:remove")
    @Log(title = "学校入驻信息", businessType = BusinessType.DELETE)
    @GetMapping("/removeSysDeptJoins")
    public com.ruoyi.common.core.web.domain.AjaxResult removeSysDeptJoins(@RequestParam Long[] deptJoinIds) {
        return toAjax(sysDeptJoinService.deleteSysDeptJoinByDeptJoinIds(deptJoinIds));
    }

    @GetMapping("/getSysDeptJoinNamesForSelect")
    //@ApiOperation(value = "获取学校入驻信息名称列表用于下拉搜索")
    public com.ruoyi.common.core.web.domain.AjaxResult getSysDeptJoinNamesForSelect() {
        List<SysDeptJoin> list = sysDeptJoinService.list();//自行加条件
        List<KeyValueVo> resultList = new ArrayList<>();
        for (SysDeptJoin sysDeptJoin : list) {
            KeyValueVo vo = new KeyValueVo();
            //vo.setKey(it.getId());
            //vo.setValue(it.getName());
            resultList.add(vo);
        }
        return com.ruoyi.common.core.web.domain.AjaxResult.success(resultList);
    }

    /**
     * 导出学校入驻信息列表
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "system:SysDeptJoin:export")
    @Log(title = "学校入驻信息", businessType = BusinessType.EXPORT)
    @GetMapping(value = "/exportSysDeptJoin", produces = "application/octet-stream")
    public String exportSysDeptJoin(HttpServletResponse response, SysDeptJoin sysDeptJoin) throws IOException {
        List<SysDeptJoin> list = sysDeptJoinService.selectSysDeptJoinList(sysDeptJoin);
        com.ruoyi.common.core.utils.poi.ExcelUtil<SysDeptJoin> util = new com.ruoyi.common.core.utils.poi.ExcelUtil<SysDeptJoin>(SysDeptJoin.class);
        util.exportExcel(response, list, "学校入驻信息数据");
        return "";
    }

}
